package com.zero.service;

import org.aopalliance.aop.Advice;
import org.springframework.aop.*;
import org.springframework.aop.support.AbstractPointcutAdvisor;
import org.springframework.aop.support.NameMatchMethodPointcut;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

//@Component
public class MyAdvisor implements PointcutAdvisor {

    @Override
    public Pointcut getPointcut() {
        NameMatchMethodPointcut pointcut = new NameMatchMethodPointcut();
        pointcut.addMethodName("test");
        return pointcut;
    }

    @Override
    public Advice getAdvice() {
        MethodBeforeAdvice advice = new MethodBeforeAdvice() {
            @Override
            public void before(Method method, Object[] args, Object target) throws Throwable {
                System.out.println("方法执行前。。。。。。。。。。。。。。。。");
            }
        };
        return advice;
    }

    @Override
    public boolean isPerInstance() {
        return false;
    }
}
